package leet.contest;

import org.junit.Test;

/**
 * @author fance
 * @date 18-6-13 上午9:53
 */
public class Main {
    public String shiftingLetters(String S, int[] shifts) {
        long[] sum = getSum(shifts);
        char[] chars = S.toCharArray();
        for (int i = 0; i < sum.length; i++) {
            if (i == chars.length) {
                break;
            }
            chars[i] = (char) ((chars[i] - 'a' + sum[i]) % 26 + 'a');
        }
        return String.valueOf(chars);
    }
    private long[] getSum(int[] shifts) {
        long[] sum = new long[shifts.length];
        int i = shifts.length - 1;
        sum[i] = shifts[i];
        i--;
        while (i >= 0) {
            sum[i] = sum[i + 1] + shifts[i];
            i--;
        }
        return sum;
    }

    @Test
    public void test() {
        String S = "bad";
        int[] shifts = {10,20,30};
        System.out.println(shiftingLetters(S,shifts));
    }
}
